
// import 'dart:html';

import 'dart:convert';
import 'dart:io';

import 'package:chewie/chewie.dart';
import 'package:date_format/date_format.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hotwork/HomePage.dart';
import 'package:flutter_hotwork/Myapplication.dart';
import 'package:flutter_hotwork/bean/BaseBean.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:flutter_hotwork/xunjian/XunJianMap.dart';
import 'package:flutter_hotwork/zhifa/QuestionListBean.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:flutter_sound/flutter_sound.dart';
import 'package:image_picker/image_picker.dart';
import 'package:video_player/video_player.dart';

import '../LoadingDialog.dart';
import '../Login.dart';
import '../Toast.dart';

// FlutterSound flutterSound = new FlutterSound();
class XunJianEndScreen extends StatefulWidget {

  @override
  XunJianEndState createState() => new XunJianEndState();

}
List<Widget> imageviews=new List();
String imgs="";
TextEditingController areaController = TextEditingController();
TextEditingController posController = TextEditingController();
TextEditingController resultController = TextEditingController();
class XunJianEndState extends State<XunJianEndScreen> {



  @override
  Widget build(BuildContext context) {
    double rpx = MediaQuery.of(context).size.width / 750;


    return Scaffold(
      appBar:new BaseViewBar(
          childView: new BaseTitleBar(
            "结束巡检",
            leftIcon: 'images/fanhui.png',
            rightIcon:  "",
            rightClick: () {
              print("点击了右边干嘛啊。。。哦");
            },
            leftClick: () {
              Navigator.of(context).pop();
              print("点击了左边干嘛啊。。。哦");
            },
          ),
          preferredSize: Size.fromHeight(50.0)),



      body:
      Container(
        child:
        Column(
          children: [
            Container(height: 10,),
            Expanded(child:
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(width: 10,),
                Text("巡检区域(必填):",style: TextStyle(color: const Color(0xFF000000),fontSize: 14),),
                Expanded(
                  child:
                  Container(
                    padding: const EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    height: 100.0,
                    decoration: new BoxDecoration(
                        color: Colors.grey[300],
                        // border: new Border.all(color: Colors.black54, width: 2.0),
                        borderRadius: new BorderRadius.circular(5.0)),
                    child:
                    // Expanded(
                    //   child:
                      new TextFormField(
                        maxLines: 5,
                        controller: areaController,
                        style: TextStyle(fontSize: 12.0, color: Colors.grey),//输入文本的样式
                        keyboardType: TextInputType.multiline,
                        decoration: InputDecoration.collapsed(hintText: '请填巡检区域'),
                      ),
                    // ),
                  ),
                ),
                Container(width: 10,),
              ],
            ),
            ),
            Container(height: 10,),
            Expanded(child:
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(width: 10,),
                Text("巡检设备(必填):",style: TextStyle(color: const Color(0xFF000000),fontSize: 14),),
                Expanded(
                  child:
                  Container(
                    padding: const EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    height: 100.0,
                    decoration: new BoxDecoration(
                        color: Colors.grey[300],
                        // border: new Border.all(color: Colors.black54, width: 2.0),
                        borderRadius: new BorderRadius.circular(5.0)),
                    child:
                    // Expanded(
                    //   child:
                      new TextFormField(
                        maxLines: 5,
                        controller: posController,
                        style: TextStyle(fontSize: 12.0, color: Colors.grey),//输入文本的样式
                        keyboardType: TextInputType.multiline,
                        decoration: InputDecoration.collapsed(hintText: '请填巡检设备'),
                      ),
                    // ),
                  ),
                ),
                Container(width: 10,),
              ],
            ),
            ),
            Container(height: 10,),
            Expanded(child:
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(width: 10,),
                Text("巡检结果(必填):",style: TextStyle(color: const Color(0xFF000000),fontSize: 14),),
                Expanded(
                  child:
                  Container(
                    padding: const EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    height: 100.0,
                    decoration: new BoxDecoration(
                        color: Colors.grey[300],
                        // border: new Border.all(color: Colors.black54, width: 2.0),
                        borderRadius: new BorderRadius.circular(5.0)),
                    child:
                    // Expanded(
                    //   child:
                      new TextFormField(
                        maxLines: 5,
                        controller: resultController,
                        style: TextStyle(fontSize: 12.0, color: Colors.grey),//输入文本的样式
                        keyboardType: TextInputType.multiline,
                        decoration: InputDecoration.collapsed(hintText: '请填巡检结果'),
                      ),
                    // ),
                  ),
                ),
                Container(width: 10,),
              ],
            ),
            ),
            Container(height: 30,),
            Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  InkWell(
                    onTap: (){
                      uptask();

                    },
                    child:
                    Container(
                      width: 200,
                      height: 30,
                      decoration: BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.all(Radius.circular(15)),
                        boxShadow: <BoxShadow>[//设置阴影
                          new BoxShadow(
                            color: Colors.blueGrey,//阴影颜色
                            // blurRadius:5.0,//阴影大小
                          ),
                        ],
                      ),
                      child:
                      Center(
                        child:
                        Text('结束巡检',style: new TextStyle(color: Colors.white)),
                      ),

                    ),
                  ),

                ]),
            Container(height: 30,),
          ],
        ),
      ),



    );
  }
  @override
  void dispose() {
    areaController..text="";
    posController..text="";
    resultController..text="";
    super.dispose();
  }
  //结束巡检
  void uptask() async {
    if(areaController.text.length>0&&posController.text.length>0&&resultController.text.length>0){
      var reqeuest =Map<Object,Object>();
      reqeuest["id"] = MyApplication.nowtaskbean.id;
      reqeuest["taskId"] = MyApplication.nowtaskbean.id;
      reqeuest["checkUser"] = MyApplication.loginuserinfo.userInfo.username;
      reqeuest["checkArea"] =  areaController.text;
      reqeuest["checkDevice"] =  posController.text;
      reqeuest["checkResult"] = resultController.text;
      try {
        Response response;
        response = await DioUtils.dio.put(DioUtils.API_PREFIX+"/checkTask/overCheckTaskById?id="+MyApplication.nowtaskbean.id.toString()+"&&checkUser="+MyApplication.loginuserinfo.userInfo.username+"&&checkArea="+areaController.text
            +"&&checkDevice="+posController.text+"&&checkResult="+resultController.text, data: json.encode(reqeuest));

        Map respMap = json.decode(response.data);
        basebean base = basebean.fromJson(respMap);
        print('响应数据：' + response.toString());
        if(base.code==0){
          LocalToast.toast(context,msg:"结束巡检成功！");
          Navigator.of(context).pop();
        } else if(base.code == 500){
          LocalToast.toast(context,msg:"会话超时，请重新登陆！");
          Navigator.pushAndRemoveUntil(
            context,
            new MaterialPageRoute(
                builder: (context) => new MyHomePage()),
                (route) => route == null,
          );
        }
      } catch (e) {
        LocalToast.toast(context,msg:"结束巡检失败！");
        print('请求出错：' + e.toString());
      }
    }else{
      LocalToast.toast(context,msg:"请填写所有必填信息！");
    }

  }

}








